'use strict'
const titbit = require('titbit');
const fs = require('fs');

const { request } = require('https');
const wxkey = require('./wxkey');
const {httpcli} = require('gohttp');
const token = require('titbit-token');
const tbloader = require('titbit-loader')
process.chdir(__dirname);

try {
    fs.accessSync('/home/zzl/images');
} catch (err) {
    fs.mkdirSync('/home/zzl/images');
}

let cert_path = '/usr/local/share';
const app = new titbit({
    debug : true,
    globalLog:true,
    timeout: 60000,
    server: {
        handshakeTimeout: 35000
    },
    cert: `${cert_path}/api.jinjin.work.pem`,
    key:`${cert_path}/api.jinjin.work.key`
})
app.use(async (c , next) => { // 设置不校验域名
    let method = ['GET','POST','PUT','DELETE','OPTIONS'];
    c.setHeader('Access-Control-Allow-Origin','*');
    c.setHeader('Access-Control-Allow-Methods',method);
    c.setHeader('Access-Control-Allow-Headers',['content-type','update','authorization','x-requested-with','isUpdate']);
    await next();
})


let tb = new tbloader();
tb.init(app);

app.addService('imagePath',`/home/zzl/images`)// 保存设计的目录
let tok = new token({
    expires:9999,//有效期为9999秒
    key:'watashidaisukikasumigaokautahaha',

    iv:'tenshisamakekkon'
});
app.options('/*',async c => {})
app.get("/",async c => {
    c.send("Kasumigaoka Utaha")
});
app.addService('tok',tok);
app.get('/decrypt/:token',async c=> {
    c.send(tok.verify(c.param.token));
})


app.run(6001);